<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据统计</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片区域 -->

    <el-card>
      <div id="main_box" style="width:750px;height:400px"></div>
    </el-card>
  </div>
</template>

<script>
import {getdata} from '../../network/getdata'
import _ from 'lodash'
import * as echarts from 'echarts'
export default {
  name:'report',
  data() {
    return {
      //需要合并的数据项
      options: {
        title: {
          text: '用户来源'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3'
            }
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            boundaryGap: false
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ]
      }
    }
  },
  methods: {
    initLine() {
      getdata({
        method:'get',
        url:'reports/type/1'
      }).then(result => {
        const res = result.data
        if(res.meta.status !== 200) {
          this.$message.error('获取图表数据失败')
          return ;
        }
        //获取数据成功
        // console.log(res.data)
        // 合并配置项
        const optionMerged = _.merge(res.data,this.options)
        this.setLine(optionMerged)
      })
    },
    //设置图表
    setLine(options) {
      //初始化容器
      let myChart = echarts.init(document.getElementById('main_box'));
      //将配置项给初始化对象
      myChart.setOption(options)
    }
  },
  created() {
    
  },
  mounted() {
    this.initLine()
  },
};
</script>

<style lang="less" scoped>
</style>